#include "iostream"
#define int long long
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
using namespace std;
static const int mod=7,n=3;
struct Matrix {
	int temp[n][n];
	Matrix(int e=0) {
		for(int i=1; i<=n-1; i++) for(int j=1; j<=n-1; j++) temp[i][j]=(j==i)*e;
	}
	Matrix mul(Matrix A,Matrix B) {
		Matrix ans(0);
		for(int i=1; i<=n-1; i++) for(int j=1; j<=n-1; j++) for(int k=1; k<=n-1; k++) ans.temp[i][j]=(ans.temp[i][j]%mod+((A.temp[i][k]%mod)*(B.temp[k][j]%mod))%mod)%mod;
		return ans;
	}
	Matrix qpow(Matrix A,int b) {
		Matrix res(1);
		while(b>0) {
			if(b&1) res=res.mul(res,A);
			b>>=1;
			A=A.mul(A,A);
		}
		return res;
	}
};
signed main() {
	_;
	int a,b,nn,dat[3]= {0,1,1},ans;
	while(cin>>a>>b>>nn) {
		if(a==0&&b==0&&nn==0) break;
		ans=0;
		Matrix A(0);
		A.temp[1][1]=a;
		A.temp[1][2]=b;
		A.temp[2][1]=1;
		A=A.qpow(A,nn-2);
		for(int i=1; i<=2; i++) ans=(ans%mod+(A.temp[1][i]%mod*dat[i]%mod)%mod)%mod;
		cout<<ans<<'\n';
	}
}
